<?php
include dirname(__FILE__) . "/config/functions.php";

$optionsQuery = mysql_query("SELECT * FROM `option`");
while($row = mysql_fetch_assoc($optionsQuery))    $options[$row['key']] = $row['value'];


if (!isset($_SESSION['advertiseImg']) && !isset($_SESSION['advertiseTxt'])) {
    header('location: advertise.php');
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $error = '';
    if ($_POST['name'] == '') {
        $error .= 'Name Field can\'t be blank.<br>';
    } elseif (strlen($_POST['name']) > 150) {
        $error .= 'Name Field can\'t exceed 150 charachters.<br>';
    }
    if ($_POST['password'] == '') {
        $error .= 'Password Field can\'t be blank.<br>';
    } elseif (strlen($_POST['password']) > 50) {
        $error .= 'Password Field can\'t exceed 50 charachters.<br>';
    }
    if ($_POST['email'] == '') {
        $error .= 'Email Field can\'t be blank.<br>';
    } elseif (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $error .= 'Invalid Email address.<br>';
    }
    if (!$error) {
        $username = mysql_real_escape_string($_POST['username']);
        $rowsu = mysql_query("SELECT username from user WHERE username = '$username'");
        if (mysql_num_rows($rowsu) > 0) {
            $error .= 'Username already exists, please enter another one.<br>';
        }
    }

    //if all valid then save and send mail.
    if (!$error) {

        $_SESSION['advertise'] = array_merge((isset($_SESSION['advertiseImg']))?$_SESSION['advertiseImg']:$_SESSION['advertiseTxt'], $_POST);
//        unset($_SESSION['advertiseImg']);
//        unset($_SESSION['advertiseTxt']);
        
        header('location: order.php');
    }
}
?>
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!-- Consider adding a manifest.appcache: h5bp.com/d/Offline -->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title><?= $options['site_name'] ?></title>
        <meta property="og:title" content="<?= $options['site_name'] ?>">
        <meta property="og:site_name" content="<?= $options['site_name'] ?>">
        <meta property="og:type" content="<?= $options['type'] ?>">
        <meta property="og:url" content="<?= $options['url'] ?>">
        <meta property="og:image" content="<?= $options['image'] ?>">
        <meta property="fb:admins" content="<?= $options['admins'] ?>">
        <meta name="description" content="<?= $options['site_description'] ?>">
        <meta name="keywords" content="<?= $options['keywords'] ?>">
        <meta name="author" content="<?= $options['author'] ?>">
        <meta name="Robots" content="<?= $options['Robots'] ?>">
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
        <link href="css/bootstrap.min.css" rel="stylesheet"/>
        <link href="css/style.css" rel="stylesheet"/>
    </head>
    <body>
        <!-- Save for Web Slices (index.psd) -->
        <table width="950" height="1" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
            <tr>
                <td background="images/bg.png">
                    <img src="images/header.png" alt="Viral Marketing Script - Your MEGA Traffic on Over-Drive!" width="950" height="294" lowsrc="Viral Marketing Script - Your MEGA Traffic on Over-Drive!"></td>
            </tr>
            <tr>
                <td background="images/bg.png"><div align="center"><strong><span class="style4">
                                :: <a href="index.php">Home</a> 
                                :: <a href="contact.php">Contact Us</a> 
                                :: <a href="advertise.php">Advertise</a> 
                                :: <a href="member/login.php">Login</a> 
                                ::</span></strong></div>
                </td>
            </tr>
            <tr>
                <td background="images/bg.png">
                    <div align="center">
                        <div class="container"> 
                            <div style="margin: 7px;"> 
                                <?php $_position = 'top'; ?>
                                <?php include dirname(__FILE__) . '/_banner.php'; ?>
                            </div>
                            <div class="row">

                                <div class="main text-center text-page"> 
                                    <h2><b>Advertise on Viral Marketing.</b></h2>
                                    <?php if (isset($_SESSION['advertiseImg'])): ?>
                                        <a href="<?= $_SESSION['advertiseImg']['impUrl'] ?>" target="_blank">
                                            <img src="<?= $_SESSION['advertiseImg']['bannerUrl'] ?>" border="0" width="468" height="60">
                                        </a>
                                        <div class="text-page-left">
                                            <p align="center"><b>If this banner is appearing ok then fill up the remaining information and press the Submit Order button otherwise go back to the previous page and change the banner.</b>
                                        </div>
                                    <?php else: ?>
                                        <a href="<?= $_SESSION['advertiseTxt']['hitUrl'] ?>" target="_blank">
                                            <?= $_SESSION['advertiseTxt']['textAd'] ?>
                                        </a>
                                        <div class="text-page-left">
                                            <p align="center"><b>If this sponsor ad is appearing ok then fill up the remaining information and press the Submit Order button otherwise go back to the previous page and change the sponsor ad.</b>
                                        </div>
                                    <?php endif; ?>
                                    <br>
                                    <?php if (isset($error)): ?>
                                        <div class="alert alert-danger alert-dismissable">
                                            <?= $error; ?>
                                        </div>
                                    <?php endif; ?> 
                                    <form action="" method="post" class="form-horizontal signupForm" role="form">
                                        <div class="form-group">
                                            <label for="yourUrl" class="col-sm-3 control-label">Your Name</label>
                                            <div class="col-sm-6">
                                                <input required='required'type="text" class="form-control" name="name" size="25" value="<?= (isset($_POST['name'])) ? $_POST['name'] : ''; ?>">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="yourUrl" class="col-sm-3 control-label">Email Address</label>
                                            <div class="col-sm-6">
                                                <input required='required'type="text" class="form-control" name="email" size="25" value="<?= (isset($_POST['email'])) ? $_POST['email'] : ''; ?>">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="yourUrl" class="col-sm-3 control-label">Tracking Password</label>
                                            <div class="col-sm-6">
                                                <input required='required'type="password" class="form-control" name="password" size="25" value="<?= (isset($_POST['password'])) ? $_POST['password'] : ''; ?>">
                                            </div>
                                            <span style="float: left; color: rgb(69, 63, 64); font-size: 11px; margin-left: 214px; margin-top: 5px;">
                                                Tracking Password is used to give you the real time results of your advertisement.
                                            </span>
                                        </div>
                                        <div class="form-group">
                                            <div style="width: 130.333%;">
                                                <button type="submit" class="btn btn-default" name="impressions">Submit Order</button>
                                            </div>
                                        </div>
                                    </form>
                                </div> 
                            </div> 
                            <br><br>
                            <div style="margin: 25px;"> 
                                <?php $_position = 'bottom'; ?>
                                <?php include dirname(__FILE__) . '/_banner.php'; ?>
                            </div>
                        </div>

                    </div>
                </td>
            </tr>
            <tr>
                <td background="images/bg.png"><div align="center">
                        <?php include dirname(__FILE__) . '/footer.php'; ?>
                    </div></td>
            </tr>
            <tr>
                <td>
                    <img src="images/footer.png" width="950" height="108" alt=""></td>
            </tr>
        </table>
        <script src="js/jquery-1.10.2.min.js"></script>
        <script src="js/bootstrap.min.js"></script>

        <!-- End Save for Web Slices -->
    </body>
</html>    